<template>
  <el-drawer
    :title="this.name"
    :visible.sync="drawer"
    :direction="direction"
    size="75%"
    :modal="false"
    @open="handleOpen"
    :before-close="handleClose">
    <el-row>
      <el-col>{{detailName}}</el-col>

      <el-col class="el-col-span">
        <span>发生次数：{{number}} 次</span>
        <span>持续时间：{{time}} 小时</span>
        <span>最早时间：{{minTime}}</span>
        <span>最晚时间：{{lastTime}}</span>
      </el-col>

      <el-col>
        <el-tabs v-model="activeName">
          <el-tab-pane label="用户管理" name="first">
            <cs-table :table-data="currentTableData"
                      :table-label="tableLabel"
                      @handleButton="handleButton"
                      @handleSortChange="handleSortChange"
                      @handleSelectionChange="handleSelectionChange"
                      :table-option="tableOption"
                      :isSelection="false"
                      class="table tableMaxHeight">
            </cs-table>
            <!-- 分页区域 -->
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pageNo"
              :page-sizes="[20, 30, 30]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
          </el-tab-pane>

          <el-tab-pane label="配置管理" name="second">
            <el-form :model="Form" ref="refForm" label-width="100px" class="form">
              <el-form-item label="输入处理记录" prop="desc" class="form-item">
                <el-input calss="form-input" type="textarea" v-model="Form.desc"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button
                  :disabled="this.Form.desc === ''"
                  icon="el-icon-circle-plus-outline"
                  type="primary"
                  size="small"
                  class="button"
                  @click="submitForm()">添加</el-button>
              </el-form-item>
            </el-form>
            <p v-if="p_show" class="form_p">{{Pvalue}}
              <span @click="deleteP">删除</span>
            </P>
            <p v-if="p_show" class="form_p">{{Pvalue}}
              <span>删除</span>
            </P>
          </el-tab-pane>

        </el-tabs>
      </el-col>

    </el-row>
  </el-drawer>
</template>

<script>
import { allDetailsData } from '@/api/alarm/all.js'
import util from '@/utils/util'
import CsTable from '@/components/cs-table'
export default {
  data() {
    return {
      p_show: false,
      drawer: false,
      direction: 'rtl',
      activeName: 'first',
      currentTableData: [],
      tableLabel: [
        { label: '发生的时间', param: 'crateTime', align: 'center', sortable: true, isShow: true },
        { label: '名称', param: 'name', align: 'center', isShow: true },
        { label: '严重程度', param: 'severity', align: 'center', sortable: false, isShow: true },
        { label: '设备IP', param: 'deviceIp', align: 'center', sortable: false, isShow: true },
        { label: '设备类型', param: 'deviceType', align: 'center', sortable: false, isShow: true },
        { label: '描述', param: 'details', align: 'center', sortable: false, isShow: true }
      ],
      tableOption: {
        label: '追溯',
        width: '120',
        options: [
          { label: '追溯', type: 'primary', size: 'mini', icon: 'el-icon-document', methods: 'audit', auth: 'sys:group:update' }
        ]
      },
      pageNo: 1,
      pageSize: 10,
      total: 0,
      Form: {
        desc: ''
      },
      Pvalue: '',
      ids: [],
      detailIds: [],
      number: '',
      lastTime: '',
      minTime: '',
      name: '',
      detailName: '',
      time: ''
    }
  },
  components: {
    CsTable
  },
  methods: {
    init(flag, ids, number, lastTime, name, detailName) {
      this.lastTime = lastTime
      this.number = number
      this.detailIds = ids
      this.name = name
      this.detailName = detailName
      this.drawer = flag
    },
    // 抽屉打开时，请求对应的数据
    handleOpen() {
      const data = {
        ids: this.detailIds.toString()
      }
      allDetailsData(data).then((res) => {
        if (res.code === 200) {
          this.currentTableData = res.data.rows
          this.minTime = res.data.minTime
          this.total = res.data.totalRows
        }
      })
      setTimeout(() => {
        const Time = util.timeDifference(this.lastTime, this.minTime)
        this.time = Math.abs(Time).toFixed(1)
      }, 100)
    },
    // 抽屉关闭
    handleClose() {
      this.drawer = false
    },
    // 处理记录的提交
    submitForm() {
      this.Pvalue = this.Form.desc
      this.$refs.refForm.resetFields()
      this.p_show = true
    },
    // 处理记录的删除
    deleteP() {
      console.log(1111)
    },
    handleButton() {
    },
    handleSortChange() {
    },
    // 多选操作
    handleSelectionChange(val) {
      // console.log(val)
      // this.ids = val.map(item => {
      //   return item.id
      // })
    },
    // 分页监听
    handleSizeChange(newSize) {
      this.pageSize = newSize
    },
    handleCurrentChange(newPage) {
      this.pageNo = newPage
    }
  }
}
</script>

<style scoped lang="scss">
  @import '~@/assets/style/public-class.scss';
  .el-row {
    padding: 20px;
  }
  .form {
    width: 100%;
    display: flex;
    align-items: center;
    margin-top: 15px;
    .form-input {
      width: 100%;
    }
  }
  .form-item {
    width: 80%;
  }
  .button {
    float: right;
    color: #fff;
    line-height: 0;
  }
  .table {
    margin: 10px 0;
  }
  .el-col-span {
    margin: 20px 0;
    span {
      font-size: 15px;
    }
  }
  span {
    margin-right: 100px;
    font-size: 14px;
  }
  .form_p {
    height: 22px;
    line-height: 22px;
    font-size: 14px;
    margin: 8px 0;
    cursor: pointer;
    padding: 0 30px;
    transition: all 0.5s;
    span {
      height: 16px;
      line-height: 18px;
      padding: 0px 10px;
      margin: 0 50px;
      font-size: 10px;
      color: #fff;
      background-color: #307dc5;
      display: none;
      border-radius: 3px;
      transition: all 0.5s;
    }
  }
  .form_p:hover {
    background-color: rgba(64, 158, 255, 0.9);
    transition: all 0.7s;
    span {
      display: inline-block;
      transition: all 3s;
    }
  }
</style>
